package com.hctforgreen.greenservice.ui.adapter;

import java.util.List;

import u.aly.bo;
import android.app.Activity;
import android.content.Context;
import android.content.IntentFilter;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import cn.dns.reader.network.Util;

import com.hctforgreen.greenservice.DownloadManagerActivityV2;
import com.hctforgreen.greenservice.R;
import com.hctforgreen.greenservice.DownloadManagerActivityV2.DownloadUpdateReceiver;
import com.hctforgreen.greenservice.ctr.DbController;
import com.hctforgreen.greenservice.model.ExamPaperEntity;
import com.hctforgreen.greenservice.model.ExamPaperEntity.PAPER_TYPE;
import com.hctforgreen.greenservice.model.StudyEntity;
import com.hctforgreen.greenservice.model.BookListEntity.BookEntity;
import com.hctforgreen.greenservice.utils.HctConstants;

/**
 * 考试试卷列表适配器
 * 
 * @author dhb 20150602
 * 
 */
public class ExamHistoryListAdapter extends BaseAdapter {

	private Activity context;
	private List<ExamPaperEntity> myList;
	private ListView mListView;

	public ExamHistoryListAdapter(Activity context,
			List<ExamPaperEntity> myList, ListView listView) {
		this.context = context;
		this.myList = myList;
		this.mListView = listView;
	}

	public int getCount() {
		return myList.size();
	}

	public Object getItem(int position) {
		return myList.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_exam_history_lst, null);
			holder.tvName = (TextView) convertView.findViewById(R.id.tv_name);
			holder.tvDate = (TextView) convertView.findViewById(R.id.tv_date);
			holder.tvCache = (TextView) convertView.findViewById(R.id.tv_cache);
			holder.tvScore = (TextView) convertView.findViewById(R.id.tv_score);
			holder.imgStatus = (ImageView) convertView
					.findViewById(R.id.img_pass_status);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		final ExamPaperEntity entity = myList.get(position);
		holder.tvName.setText(entity.name);
		holder.tvDate.setText(entity.createTime);

		if (entity.paperType == PAPER_TYPE.TYPE_CACHE) {// 草稿
			holder.tvCache.setVisibility(View.VISIBLE);
			holder.imgStatus.setVisibility(View.GONE);
			holder.tvScore.setText("-");
		} else {
			if (entity.isPass == 0) {// 考试成绩为通过
				holder.imgStatus
						.setImageResource(R.drawable.ic_exam_his_unpass);
			} else {
				holder.imgStatus.setImageResource(R.drawable.ic_exam_his_pass);
			}
			holder.imgStatus.setVisibility(View.VISIBLE);
			holder.tvScore
					.setText(context
							.getString(R.string.exam_history_score_hint)
							+ entity.score);
			holder.tvCache.setVisibility(View.GONE);// 提交到后台的记录
		}
		return convertView;
	}

	static class ViewHolder {
		TextView tvName;// 名称
		TextView tvDate;// 时间
		TextView tvScore;// 得分
		ImageView imgStatus;// 考试结果
		TextView tvCache;// 草稿
	}

}